<script setup lang="ts">
import { safe_request } from "@/server/safe_request";
import { ref } from "vue";
import { showToast, sleep } from "@/common/utils/utils";
import { throttle } from "lodash";

const loading = ref(false);

const getData = throttle(async () => {
  loading.value = true;
  try {
    const res = await safe_request.get("api/sugrec?&prod=pc&wd=1");
    console.log(res);
  } catch (error) {
  } finally {
    await sleep(1500);
    loading.value = false;
  }
}, 2000);

const handleToast = async () => {
  showToast("我是toast");
};
</script>

<template>
  <view class="content p-xs">
    <wd-button @click="getData" :loading="loading">发起请求</wd-button>
    <wd-button @click="handleToast">showToast</wd-button>
  </view>
</template>

<style scoped lang="scss">
.content {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}
</style>
